let themeId;

window.onload = function () {
    themeId = getQuery("themeId");
    fullTheme();
}

async function fullTheme() {
    let userId;
    await axios.get("/theme/findById", {
        params: {
            id: themeId
        }
    }).then(resp => {
        let info = resp.data;
        $("themeName").innerHTML = info.name;
        $("themeContent").innerHTML = info.content;
        userId = info.user.id;

        let str = "评论区：<br>";
        info.list.forEach(n => {
            str += `<span>评论人：${n.user.nickname}</span><br>
                    <span>评论内容：${n.content}</span><br>`;
        })
        $("comment").innerHTML = str;
    });

    axios.get("/user/findById", {
        params: {
            id: userId
        }
    }).then(resp => {
        let info = resp.data;
        $("photo").src = "/face/" + info.imgPath;
        $("nicknameSpan").innerHTML = info.nickname;
        $("dateSpan").innerHTML = info.date;
    });


}

async function add() {
    let loginUserId;
    await axios.get("/user/getUser").then(resp => {
        let info = resp.data;
        loginUserId = info.id;
    });
    axios.get("/comment/add", {
        params: {
            name: $("commentName").value,
            content: $("commentContent").value,
            userId: loginUserId,
            themeId
        }
    }).then(resp => {
        let info = resp.data;
        if (info != null) {
            fullTheme();
        }
    });
}